<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-body">
              <div class="layui-form" lay-filter="">

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">优惠券名称</label>
                    <div class="layui-input-inline">
                      <input type="text" name="name" placeholder="请输入优惠券名称" v-model="itemData.name" autocomplete="off"
                        class="layui-input" disabled="ture" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">优惠券类型</label>
                  <div class="layui-input-inline">
                    <select name="couponType" lay-filter="couponType" v-model="itemData.couponType" disabled="ture">
                      <option value="QUOTA">定额</option>
                      <option value="QUOTA_LIMIT_CATEGORYID">限品类定额</option>
                      <option value="QUOTA_LIMIT_GOODID">限商品定额</option>
                      <option value="CONSUPTION_QUOTA">满额减</option>
                      <option value="CONSUPTION_QUOTA_LIMIT_CATEGORYID">限品类满额减</option>
                      <option value="CONSUPTION_QUOTA_LIMIT_GOODID">限商品满额减</option>
                      <option value="CONSUPTION_DISCOUNT">满额折扣</option>
                      <option value="CONSUPTION_DISCOUNT_LIMIT_CATEGORYID">限品类满额折扣</option>
                      <option value="CONSUPTION_DISCOUNT_LIMIT_GOODID">限商品满额折扣</option>
                      <option value="COUNT_DISCOUNT">满几件折扣</option>
                      <option value="COUNT_DISCOUNT_LIMIT_CATEGORYID">限品类满几件折扣</option>
                      <option value="QUOTA_LIMIT_GOODID">限商品满几件折扣</option>
                      <option value="EVERY_CONSUPTION_QUOTA">每满多少减多少</option>
                      <option value="EVERY_CONSUPTION_QUOTA_LIMIT_CATEGORYID">限品类每满多少减多少</option>
                      <option value="EVERY_CONSUPTION_QUOTA_LIMIT_GOODID">限商品每满多少减多少</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">限定数据</label>
                    <div class="layui-input-inline">
                      <input type="number" name="ruleLimitData " placeholder="" v-model="itemData.ruleLimitData "
                        autocomplete="off" class="layui-input" disabled="ture" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">优惠数据</label>
                    <div class="layui-input-inline">
                      <input type="number" name="ruleFavourData " placeholder="" v-model="itemData.ruleFavourData "
                        autocomplete="off" class="layui-input" disabled="ture" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">顾客限量</label>
                    <div class="layui-input-inline">
                      <input type="number" name="customerLimitAmount " placeholder="请输入顾客限量"
                        v-model="itemData.customerLimitAmount " autocomplete="off" class="layui-input" min="0"
                        disabled="ture" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">发行总量</label>
                    <div class="layui-input-inline">
                      <input type="number" name="totalAmount" placeholder="请输入发行总量" v-model="itemData.totalAmount"
                        autocomplete="off" class="layui-input" min="0" disabled="ture" />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                      <input type="text" name="beginAt" class="layui-input" placeholder="年-月-日-时-分-秒"
                        v-model="itemData.beginAt" disabled="ture">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">过期时间</label>
                    <div class="layui-input-inline">
                      <input type="text" name="expireAt" class="layui-input" placeholder="年-月-日-时-分-秒"
                        v-model="itemData.expireAt" disabled="ture">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item layui-form-text">
                  <label class="layui-form-label">优惠券备注</label>
                  <div class="layui-input-block" style="width:380px">
                    <textarea placeholder="请输入内容" class="layui-textarea" v-model="itemData.summary"
                      disabled="ture"></textarea>
                  </div>
                </div>

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "yhjlist",
  data () {
    return {
      id: "",
      itemData: {
        name: "", //优惠券名称
        summary: "", // 优惠券概述
        couponType: "", // 优惠券类型
        ruleLimitData: "",//限定数据
        ruleFavourData: "",//优惠数据
        customerLimitAmount: "",//顾客限量
        totalAmount: "",//发行总量
        beginAt: "",//使用开始时间
        expireAt: "",//过期时间  
      },
      type: localStorage.getItem("type"),
    };
  },
  mounted () {
    var vm = this;
    window.getdates = this.getdates;
  },
  methods: {
    getdates: function (data) {
      var vm = this;
      if (vm.type == '1') {
        var url = "/coupon/aapi/v1.9/publishes/" + data.id;
      } else {
        var url = "/crm/bapi/v1.9/publish/" + data.id;
      }
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        if (ret.data != null) {
          vm.itemData = ret.data;
          vm.itemData.ruleLimitData = ret.data.ruleLimitData/100;
          vm.itemData.ruleFavourData = ret.data.ruleFavourData/100;
          var beginAt = ret.data.beginAt;
      var expireAt = ret.data.expireAt;
      vm.itemData.beginAt = FormatDate(beginAt,3);
      vm.itemData.expireAt = FormatDate(expireAt,3);
        }
      });
    },

  },
  updated: function () {
    var vm = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
      form.on("select(couponType)", function (data) {
        vm.itemData.couponType = data.value;
      });
    });
  },
};
</script>
<style scoped>
.notes {
  color: #999;
}
</style>
